package com.cratos.xxgram.platf.friend;

import com.cratos.xxgram.platf.base.UserInfo;
import java.io.Serializable;
import javax.persistence.*;
import org.redkale.convert.json.*;
import org.redkale.source.DistributeTableStrategy;
import org.redkale.source.FilterNode;
import org.redkale.source.Range;

/**
 *
 * @author zhangjx
 */
@Table(comment = "已删除的好友")
public class FriendShipHis extends FriendShip {
    
    @Id
    @Column(length = 64, comment = "记录ID 值=create36time(9位)+UUID(32位)")
    private String seqid = "";
    
    @Column(length = 64, comment = "userid+“-”+friendid ")
    private String friendshipid = "";

    @Column(comment = "用户ID")
    private int userid;

    @Column(comment = "好友ID")
    private int friendid;

    @Column(length = 64, comment = "好友的备注名")
    private String friendname = "";

    @Column(length = 255, comment = "备注信息")
    private String remark = "";

    @Column(comment = "加好友方式; 10:手机搜索; 20:扫二维码;")
    private short invitetype;

    @Column(updatable = false, comment = "加好友时间")
    private long createtime;

    @Column(comment = "删除时间")
    private long deletetime;

      
    @Transient
    private UserInfo friend;
    
    @Transient
    private  boolean isfriend = true;

    public String getSeqid() {
        return seqid;
    }

    public void setSeqid(String seqid) {
        this.seqid = seqid;
    }

    public long getDeletetime() {
        return deletetime;
    }

    public void setDeletetime(long deletetime) {
        this.deletetime = deletetime;
    }
    
    
    public String getFriendshipid() {
        return friendshipid;
    }

    public void setFriendshipid(String friendshipid) {
        this.friendshipid = friendshipid;
    }

    public int getUserid() {
        return userid;
    }

    public void setUserid(int userid) {
        this.userid = userid;
    }

    public int getFriendid() {
        return friendid;
    }

    public void setFriendid(int friendid) {
        this.friendid = friendid;
    }

    public String getFriendname() {
        return friendname;
    }

    public void setFriendname(String friendname) {
        this.friendname = friendname;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public short getInvitetype() {
        return invitetype;
    }

    public void setInvitetype(short invitetype) {
        this.invitetype = invitetype;
    }

    public long getCreatetime() {
        return createtime;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
    }

    public UserInfo getFriend() {
        return friend;
    }

    public void setFriend(UserInfo friend) {
        this.friend = friend;
    }

    public boolean isIsfriend() {
        return isfriend;
    }

    public void setIsfriend(boolean isfriend) {
        this.isfriend = isfriend;
    }
    
    
    public static class TableStrategy implements DistributeTableStrategy<FriendShipHis> {

        private static final String format = "%1$tY%1$tm";

        @Override
        public String getTable(String table, FriendShipHis bean) {
            return table + "_" + String.format(format, bean.getCreatetime());
        }

        @Override
        public String getTable(String table, Serializable primary) {
            String id = (String) primary;
            return getTable(table, Long.parseLong(id.substring(0, 9), 36));
        }

        @Override
        public String getTable(String table, FilterNode node) {
            Range.LongRange createtime = (Range.LongRange) node.findValue("createtime");
            return getTable(table, createtime.getMin());
        }

        private String getTable(String table, long createtime) {
            int pos = table.indexOf('.');
            return table.substring(pos + 1) + "_" + String.format(format, createtime);
        }
    }
}
